<template>
  <page-header-wrapper>
    <GlobalSearch :list="searchList" @search="handleSearch" @reset="handleReset"> </GlobalSearch>
    <a-card :bordered="false">
      <div class="table-header m-b-24"></div>
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record)">查看</y-button>
          <y-button type="link" @click="handleSignContract(record)">合同签订</y-button>
        </div>
      </s-table>
    </a-card>
    <sign-contract
      :visible.sync="visibleSign"
      :data.sync="proposer"
      title="补签合同"
      pactClass="补签合同"
      @success="tableRefresh(true)"
    ></sign-contract>
    <detail :visible.sync="visibleDetail" :data.sync="proposer"></detail>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, buttonSelect, signContract } from '@/components'
import { getContractNewOrSupplement } from '@/api/followUpManagement'
import detail from '../newContract/components/detail.vue'
import moment from 'moment'
export default {
  components: {
    STable,
    Ellipsis,
    buttonSelect,
    signContract,
    detail,
  },
  data() {
    return {
      proposer: {},
      visibleSign: false,
      visibleDetail: false,
      queryParam: {
        PactClass: '补签合同',
        strContent: {},
        DeptNO: this.$store.getters.userInfo.DeptNO,
      },
      searchList: [
        {
          label: '申请编号',
          fields: 'ApplyNO',
          type: 'input',
          props: {
            placeholder: '请输入申请编号',
          },
        },
        {
          label: '申请人姓名',
          fields: 'Proposer',
          type: 'input',
          props: {
            placeholder: '请输入申请人姓名',
          },
        },
        {
          label: '身份证号',
          fields: 'IDcard',
          type: 'input',
          props: {
            placeholder: '请输入身份证号',
          },
        },
        {
          label: '房屋地址',
          fields: 'EsitesSelect',
          type: 'input',
          props: {
            placeholder: '请输入房屋地址',
          },
        },
        {
          label: '预分配日期',
          fields: 'date',
          type: 'range',
          props: {
            valueFormat: 'YYYY-MM-DD',
          },
        },
      ],
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '房屋所属',
          align: 'center',
          dataIndex: 'HouseCat',
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDcard',
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'Phone',
        },
        {
          title: '保障方式',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '补贴方式',
          align: 'center',
          dataIndex: 'CityVfyAssign',
        },
        {
          title: '预分配地址',
          align: 'center',
          dataIndex: 'EsitesSelect',
          customRender: (text) => <ellipsis length={24}>{text}</ellipsis>,
        },
        {
          title: '签订日期',
          align: 'center',
          dataIndex: 'EsetDate',
          customRender: (text) => moment(text).format('YYYY-MM-DD'),
        },
        {
          title: '操作',
          align: 'center',
          width: '140px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getContractNewOrSupplement(requestParameters).then((res) => res)
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      if (!this.$isEmpty(values.date)) {
        this.queryParam.strContent.EsetDate = values.date[0]
        this.queryParam.strContent.EndTime = values.date[1]
      }
      delete this.queryParam.strContent.date
      this.tableRefresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.tableRefresh(true)
    },
    tableRefresh(refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleDetail(record) {
      this.proposer = record
      this.visibleDetail = true
      // this.$router.push({
      //   name: 'assureInformationView',
      //   params: {
      //     id
      //   }
      // })
    },
    handleSignContract(record) {
      this.proposer = record
      this.visibleSign = true
    },
  },
}
</script>
<style lang="less" scoped></style>
